import React, {Component} from 'react';
import {NavigationContext} from '@react-navigation/native';

// 获取组件的名字
const getDisplayName = (WrappedComponent) =>
  WrappedComponent.displayName || WrappedComponent.name || 'Component';

export const Navigation = (WrappedComponent) => {
  class Context extends Component {
    static contextType = NavigationContext;
    render() {
      const navigation = this.context;
      return <WrappedComponent {...this.props} navigation={navigation} />;
    }
  }
  Context.displayName = `HOC(${getDisplayName(WrappedComponent)})`;
  return Context;
};
